package com.czk.client;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;

import java.util.concurrent.TimeUnit;

/**
 * 监听器
 *
 * @Author:ChenZhangKun
 * @Date: 2021/4/28 11:12
 */
public class MyChannelFutureListener implements ChannelFutureListener {
    @Override
    public void operationComplete(ChannelFuture channelFuture) throws Exception {
        if (channelFuture.isSuccess()) {
            System.out.println("连接成功");
            return;
        }
        EventLoop eventLoop = channelFuture.channel().eventLoop();
        eventLoop.schedule(() -> {
            try {
                new NettyClient().connect("localhost", 7379);
                System.out.println("休眠");
                Thread.sleep(500);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }, 1L, TimeUnit.SECONDS);
    }
}
